﻿/*
 * Copyright © 2010 Project Mercury Team Members (http://mpe.codeplex.com/People/ProjectPeople.aspx)
 * 
 * This program is licensed under the Microsoft Permissive License (Ms-PL). You should
 * have received a copy of the license along with the source code. If not, an online copy
 * of the license can be found at http://mpe.codeplex.com/license.
 */

namespace ProjectMercury.Controllers
{
    using System;
    using System.ComponentModel;

    /// <summary>
    /// Defines a controller which adjusts the release quantity of a trigger to represent particles
    /// released per second.
    /// </summary>
    [TypeDescriptionProvider("ProjectMercury.Design.TypeDescriptorFactory, ProjectMercury.Design, Version=4.0.0.0")]
    public class TimedReleaseQuantityController : AbstractController
    {
        /// <summary>
        /// Copies the properties of this instance into the specified existing instance.
        /// </summary>
        /// <param name="existingInstance">An existing controller instance.</param>
        protected override AbstractController DeepCopy(AbstractController existingInstance)
        {
            var value = (existingInstance as TimedReleaseQuantityController) ?? new TimedReleaseQuantityController();

            return value;
        }

        /// <summary>
        /// Adds additional logic to an emitter trigger event.
        /// </summary>
        /// <param name="deltaSeconds">Elapsed time in whole and fractional seconds.</param>
        /// <param name="context">The trigger context.</param>
        public override void Process(Single deltaSeconds, ref TriggerContext context)
        {
            context.ReleaseQuantity = Math.Max((Int32)((Single)context.ReleaseQuantity * deltaSeconds), 1);
        }
    }
}